<?xml version='1.0'?>
<!--=======================================================================
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington
	Started:	2008-06-14
	Status:		release	
	Version:	2.0.0
	Build:		20080614
	License:	GNU General Public License
	======================================================================= -->

<!--=======================================================================
	Development Notes:
	==================
	20080614:	Initial release.
	=======================================================================	-->

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
	
	<xsl:template match="blogspace" mode="shop">
		<xsl:call-template name="Intro">
			<xsl:with-param name="type">custom</xsl:with-param>
			<xsl:with-param name="title">WebsiteX shop</xsl:with-param>
			<xsl:with-param name="pic">products</xsl:with-param>
		</xsl:call-template>
		
		<div id="other_content">
			<xsl:for-each select="//content/blogspace/topics/topic[@blogs='yes' and @name != 'default']">
				<div class="shop-cat_entry">
					<div class="shop-cat-left">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="$BaseLinkUrl"/>
								<xsl:text>site_shop_cat</xsl:text>
								<xsl:text>&amp;topic=</xsl:text>
								<xsl:value-of select="./@name"/>
								<xsl:text>&amp;topics=</xsl:text>
								<xsl:value-of select="./@name"/>
							</xsl:attribute>
							<img width="132">
								<xsl:attribute name="src">
									<xsl:text>admin/images/</xsl:text>
									<xsl:value-of select="blog/image"/>
								</xsl:attribute>
							</img>
						</a>
					</div>
					<div class="shop-cat-right">
						<div class="shop-cat-intro">
							<h2>
								<xsl:value-of select="blog/title"/>
							</h2>
						</div>
						<div class="paranorm">
							<xsl:value-of select="blog/bloghtml"/>
							<xsl:text> </xsl:text>
						</div>
						<div class="shop-cat-more">
							<a>
								<xsl:attribute name="href">
									<xsl:value-of select="$BaseLinkUrl"/>
									<xsl:text>site_shop_cat</xsl:text>
									<xsl:text>&amp;topic=</xsl:text>
									<xsl:value-of select="./@name"/>
									<xsl:text>&amp;topics=</xsl:text>
									<xsl:value-of select="./@name"/>
								</xsl:attribute>
								<xsl:text>View Products</xsl:text>
							</a>
						</div>
					</div>
				</div>
			</xsl:for-each>
		</div>
	</xsl:template>

	<xsl:template match="blogspace" mode="shop-cat">
		<xsl:call-template name="Intro">
			<xsl:with-param name="type">custom</xsl:with-param>
			<xsl:with-param name="title">
				<xsl:text>Shop Cart - </xsl:text>
				<xsl:value-of select="//topics/topic[@name=$topic]/blog/title"/>
			</xsl:with-param>
		</xsl:call-template>
		
		<div id="paragraphs">
			<xsl:value-of select="topics/topic/blog/bloghtml"/>
		</div>
		<xsl:apply-templates select="topics/topic[@name=$topic]/blogs/blog" mode="shop-cat-detail">
			<xsl:sort data-type="text" order="descending" select="date/@create"/>
			<xsl:with-param name="topic">
				<xsl:value-of select="//topics/topic[@name=$topic]/@name"/>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="blogs/blog" mode="shop-cat-detail">
		<xsl:param name="topic"/>
		<div class="shop-cat-detail_entry">
			<div class="shop-cat-detail-left">
				<img width="132">
					<xsl:attribute name="src">
						<xsl:text>images/shop/</xsl:text>
						<xsl:value-of select="$topic"/>
						<xsl:text>/</xsl:text>
						<xsl:value-of select="@id"/>
						<xsl:text>.gif</xsl:text>
					</xsl:attribute>
				</img>
			</div>
			<div class="shop-cat-detail-right">
				<div class="shop-cat-detail-intro">
					<h2>
						<xsl:value-of select="title"/>
					</h2>
				</div>
				<div class="paranorm">
					<xsl:apply-templates select="bloghtml"/>
				</div>
				<div class="shop-item-price">
					<xsl:text>Suggested price R</xsl:text>
					<xsl:value-of select="suggestedPrice"/>
					<xsl:text> | Our price R</xsl:text>
					<xsl:value-of select="price"/>
				</div>
				<div class="shop-functions">
					<script type="text/javascript">
						<xsl:text>function validateForm(frm){x_valid.Debug("_Validate");try{if (!x_valid.Text(frm.addItemQuantity, "Please specify a valid number of products."))return false;}catch(e){x_valid.Debug("_validateForm", "error", (typeof(e)=="string")? e : e.description);return false;};x_form.SubmitOnce('FormX</xsl:text>
						<xsl:value-of select="@id"/>
						<xsl:text>');return true;}	</xsl:text>			
					</script>
					<form onkeypress="x_form.KeyPress(this)" method="post" >
						<xsl:attribute name="action">
							<xsl:value-of select="$BaseLinkUrl"/>
							<xsl:value-of select="$link"/>
							<xsl:text>&amp;topics=</xsl:text>
							<xsl:value-of select="$topic"/>
							<xsl:text>&amp;topic=</xsl:text>
							<xsl:value-of select="$topic"/>
						</xsl:attribute>
						<xsl:attribute name="name">
							<xsl:text>formx</xsl:text>
							<xsl:value-of select="@id"/>
						</xsl:attribute>
						<img src="../images/add-icon.gif" alt="Add"/>
						<xsl:text>&#160;&#160;</xsl:text>
						<xsl:text> Add </xsl:text>
						<input type="hidden" name="addItemPrice">
							<xsl:attribute name="value"><xsl:value-of select="price"/></xsl:attribute>
						</input>

						<input type="hidden" name="addItemName">
							<xsl:attribute name="value"><xsl:value-of select="title"/></xsl:attribute>
						</input>
						<input type="hidden" name="addItemId" value="1">
							<xsl:attribute name="value">
								<xsl:value-of select="$topic"/>
								<xsl:value-of select="@id"/>
							</xsl:attribute>
						</input>
						<input type="input" name="addItemQuantity" style="width:30px" value="1"/>
						<xsl:text> to cart </xsl:text>
						<input type="Button" class="fm-btn" value="Add">
							<xsl:attribute name="onClick">
								<xsl:text>javascript:x_form.Check('FormX</xsl:text>
								<xsl:value-of select="@id"/>
								<xsl:text>','valid',validateForm)</xsl:text>
							</xsl:attribute>
						</input>
					</form>
				</div>
			</div>
		</div>
	</xsl:template>




	<xsl:template match="content/profile/shopcart" mode="ProductEditTable">

		<xsl:call-template name="Intro">
			<xsl:with-param name="type">custom</xsl:with-param>
			<xsl:with-param name="title">Edit Shopping cart</xsl:with-param>
		</xsl:call-template>
		
		<div id="edit-screen-content"	>
			<table id="product-edit-table">
				<tr>
					<td class="top"></td>
					<td class="top">Quantity</td>
					<td class="top">Unit Price</td>
					<td class="top">Subtotal</td>
					<td class="top"></td>
				</tr>
				<xsl:for-each select="item">
					<xsl:variable name="white">
						<xsl:choose>
							<xsl:when test="position() mod 2 = 0"></xsl:when>
							<xsl:otherwise>white</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<tr>
						<td>
							<xsl:attribute name="class"><xsl:text>item-name </xsl:text><xsl:value-of select="$white"/></xsl:attribute>
							<xsl:value-of select="name"/>
						</td>
						<td>
							<xsl:attribute name="class"><xsl:text>item-quantity </xsl:text><xsl:value-of select="$white"/></xsl:attribute>
							<input type="input" class="edit-table-inp">
								<xsl:attribute name="value"><xsl:value-of select="quantity"/></xsl:attribute>
							</input>
							<p class="right-align">
								<a>
									<xsl:attribute name="href">
										<xsl:value-of select="$BaseLinkUrl"/>
										<xsl:text>shopcart_edit_plus&amp;editId=</xsl:text>
										<xsl:value-of select="@id"/>
									</xsl:attribute>
									<xsl:text>+</xsl:text>
								</a>
								<xsl:text> 1 </xsl:text>
								<a>
									<xsl:attribute name="href">
										<xsl:value-of select="$BaseLinkUrl"/>
										<xsl:text>shopcart_edit_minus&amp;editId=</xsl:text>
										<xsl:value-of select="@id"/>
									</xsl:attribute>
									<xsl:text>-</xsl:text>
								</a>
							</p>
						</td>
						<td>
							<xsl:attribute name="class"><xsl:text>item-price </xsl:text><xsl:value-of select="$white"/></xsl:attribute>
							<xsl:text>R </xsl:text>
							<xsl:value-of select="price"/>
						</td>
						<td>
							<xsl:attribute name="class"><xsl:text>item-subtotal </xsl:text><xsl:value-of select="$white"/></xsl:attribute>
							<xsl:text>R </xsl:text>
							<xsl:value-of select="subtotal"/>
						</td>
						<td>
							<xsl:attribute name="class"><xsl:text>item-delete </xsl:text><xsl:value-of select="$white"/></xsl:attribute>
							<a>
								<xsl:attribute name="href">
									<xsl:value-of select="$BaseLinkUrl"/>
									<xsl:text>shopcart_del&amp;delId=</xsl:text>
									<xsl:value-of select="@id"/>
								</xsl:attribute>
								<xsl:text>Delete</xsl:text>
							</a>
						</td>
					</tr>
				</xsl:for-each>
				 <tr>
					<td class="bottom"></td>
					<td class="bottom"></td>
					<td class="bottom"><xsl:text>Total:</xsl:text></td>
					<td class="bottom"><xsl:text>R </xsl:text><xsl:value-of select="sum(item/subtotal)"/></td>
				</tr>
			</table>
		</div>
	</xsl:template>

	<xsl:template match="content/profile/shopcart" mode="ProductDisplayTable">
		<xsl:call-template name="Intro">
				<xsl:with-param name="type">custom</xsl:with-param>
				<xsl:with-param name="title">Checkout step 1 of 2</xsl:with-param>
				<xsl:with-param name="pic">products</xsl:with-param>
		</xsl:call-template>
		<div id="edit-screen-content"	>
			<table id="product-edit-table">
				<tr>
					<td colspan="4" class="split">Your order</td>
				</tr>
				<tr>
					<td class="top"></td>
					<td class="top">Quantity</td>
					<td class="top">Unit Price</td>
					<td class="top">Subtotal</td>
				</tr>
				<xsl:for-each select="item">
					<xsl:variable name="white">
						<xsl:choose>
							<xsl:when test="position() mod 2 = 0"></xsl:when>
							<xsl:otherwise>white</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<tr>
						<td>
							<xsl:attribute name="class">
								<xsl:text>item-name </xsl:text>
								<xsl:value-of select="$white"/>
							</xsl:attribute>
							<xsl:value-of select="name"/>
						</td>
						<td>
							<xsl:attribute name="class">
								<xsl:text>item-quantity </xsl:text>
								<xsl:value-of select="$white"/>
							</xsl:attribute>
							<xsl:value-of select="quantity"/>
						</td>
						<td>
							<xsl:attribute name="class">
								<xsl:text>item-price </xsl:text>
								<xsl:value-of select="$white"/>
							</xsl:attribute>
							<xsl:text>R </xsl:text>
							<xsl:value-of select="price"/>
						</td>
						<td>
							<xsl:attribute name="class">
								<xsl:text>item-subtotal-display </xsl:text>
								<xsl:value-of select="$white"/>
							</xsl:attribute>
							<xsl:text>R </xsl:text>
							<xsl:value-of select="subtotal"/>
						</td>
					</tr>
				</xsl:for-each>
				<tr>
					<td class="bottom"></td>
					<td class="bottom"></td>
					<td class="bottom"><xsl:text>Total:</xsl:text></td>
					<td class="bottom"><xsl:text>R </xsl:text><xsl:value-of select="sum(item/subtotal)"/></td>
				</tr>
			</table>
		</div>
	</xsl:template>
	
	
	

	<xsl:template match="profile/shopcart">
		<xsl:if test="not(/content/website/links/link[@name=$link]/@shopcart='no')">
			<div id="shopcartbox">
				<xsl:choose>
					<xsl:when test="count(item) = 0 and $link != 'site_shop_cat' and $link != 'shopcart'">
						<!-- Display the banner if there are no products in cart-->
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="$BaseLinkUrl"/>
								<xsl:text>shopcart</xsl:text>
							</xsl:attribute>
							<img src="images/shopcart_banner.jpg" alt="Visit our online store"/>
						</a>
					</xsl:when>
					<xsl:otherwise>
						<h3>Shopping Cart</h3>
						<!-- Get the contents of the shopping cart<div class="top"><xsl:call-template name="nobrspace"/></div>-->
						<div id="shopcart-body">
    						<xsl:if test="count(item) != 0">
								<p>In your cart:</p>
							</xsl:if>
							<table>
								<xsl:choose>
									<xsl:when test="count(item) = 0">
										<tr>
											<td><xsl:text>Your cart is empty</xsl:text></td>
										</tr>  
									</xsl:when>
									<xsl:otherwise>
										<xsl:for-each select="item">
											<xsl:variable name="white">
												<xsl:choose>
													<xsl:when test="position() mod 2 = 0"></xsl:when>
													<xsl:otherwise>white</xsl:otherwise>
												</xsl:choose>
											</xsl:variable>
												<tr>
													<td>
														<xsl:attribute name="class">
															<xsl:text>item-quantity </xsl:text>
															<xsl:value-of select="$white"/>
														</xsl:attribute>
														<xsl:value-of select="quantity"/>
													</td>
													<td>
														<xsl:attribute name="class">
															<xsl:text>item-name </xsl:text>
															<xsl:value-of select="$white"/>
														</xsl:attribute>
														<xsl:value-of select="name"/>
													</td>
												</tr>
										</xsl:for-each>
									</xsl:otherwise>
								</xsl:choose>
							</table>
							<xsl:if test="count(item) != 0">
								<div id="shopcart-bottom">
									<form onkeypress="x_form.KeyPress(this)" method="post" name="FormXShopCart">
										<xsl:attribute name="action">
											<xsl:value-of select="$BaseLinkUrl"/>
											<xsl:text>shopcart_checkout1</xsl:text>
										</xsl:attribute>
										<input type="Button" class="fm-btn" value="Checkout" onClick="javascript:x_form.Check('FormXShopCart','valid',null)" />
									</form>
									<a>
										<xsl:attribute name="href">
											<xsl:value-of select="$BaseLinkUrl"/>
											<xsl:text>shopcart_edit</xsl:text>
										</xsl:attribute>
										<xsl:text>Edit your cart</xsl:text>
									</a>
								</div>
							</xsl:if>
						</div>
					</xsl:otherwise>
				</xsl:choose>
			</div>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>